import matplotlib
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt

matplotlib.use('TkAgg')
vertices = pd.read_csv("E:\\yhm\\part2.csv")
edges = pd.read_csv("E:\\yhm\\part1.csv")
G = nx.DiGraph()
for _, row in vertices.iterrows():
    G.add_node(row['id'], name = row['name'])
    for _, row in edges.iterrows():
        G.add_edge(row['src'], row['dst'], label = row['relationship'])

        plt.figure(figsize=(8,6))
        pos = nx.spring_layout(G)
        labels = {node: data['name'] for node, data in G.nodes(data=True)}
        edge_labels={(u, v):d['label']
        for u, v, d in G.edges(data=True)}
        mx.draw_networkx_nodes(G, pos, node_size=2000, node_color='lightblue')
        mx.draw_networkx_edges(G, pos, arrowstyle='->', arrowsize=20)
        mx.draw_networkx_labels(G, pos, labels-labels, font_size=12)
        mx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels)

        plt.title("Social Network Analysis")
        plt.axis('off')
        plt.show()
